app.factory('accessTokenInterceptor', function ($injector, $window) {
    var tokenInjector = {
        response: function(response) {
            // 保存response中的token
            // if(response.data != null && response.data != undefined){
            //     if(response.data.data != null && response.data.data != undefined){
            //         if(response.data.data.Authorization != null && response.data.data.Authorization != undefined)
            //             // document.cookie = response.data.data.Authorization;
            //             setCookie('token',response.data.data.Authorization,-1);
            //     }
            // }
            //拦截器实现超时跳转到登录页面
            // 通过xhr取得响应头
            var REDIRECT = response.headers("REDIRECT_");
            //如果响应头中包含 REDIRECT 则说明是拦截器返回的
            if (REDIRECT == "REDIRECT_")
            {
                var win = window;
                while (win != win.top)
                {
                    win = win.top;
                }
                //重新跳转到 login
                win.location.href = response.headers("CONTENTPATH_");
            }
            return response;
        }
    };
    return tokenInjector;
});

app.config(function ($httpProvider) {
    $httpProvider.interceptors.push('accessTokenInterceptor');
});